package com.cby.leetcode.二分查找.LC2529;

/**
 * ClassName: LC2529
 * Package: com.cby.leetcode.二分查找.LC2529
 * Description:
 *
 * @Author dhu-bion
 * @Create 2025/9/11 16:40
 * @Version 1.0
 */
public class LC2529 {

    /**
     * 二分查找：lowBound
     */

    //问题转换为找>0和<0数量
    static class Solution{
        public int maximumCount(int[] nums){
            //1.>0,转为>=1
            int len1 = nums.length - this.lowBounds(nums, 1);
            //2.<0
            int len2 = this.lowBounds(nums, 0);

            int count = len1 > len2 ? len1 : len2;
            return count;
        }

        private int lowBounds(int[] nums,int target){
            int left = 0;
            int right = nums.length - 1;
            int mid;

            while (left <= right){
                mid = left + (right - left) / 2;
                if(nums[mid] >= target)
                    right = mid - 1;
                else
                    left = mid + 1;
            }

            return left;
        }
    }

}
